package nowcoder;

import java.util.Scanner;

public class 空瓶换水喝 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String input;
        while (scan.hasNext()) {
            input = scan.next();
            if ("0".equals(input)) {
                return;
            }
            System.out.println(exchange(Integer.parseInt(input)));
        }
    }

    public static int exchange(int emptyCount) {
        int count = 0;
        while (emptyCount >= 3) {
            int devide = emptyCount / 3;
            count += devide;
            emptyCount = devide + emptyCount % 3;
        }

        return emptyCount == 2 ? count + 1 : count;
    }
}